package com.dtf.admin.manage.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping(value="/index")
@RestController
public class IndexController {
	@Autowired
	private HttpServletRequest request;
	
	@RequestMapping
	public String hi() {
		if (request.getSession().getAttribute("test") == null) {
			request.getSession().setAttribute("test", "11111111111");
			System.out.println("设置session.");
		}else{
			System.out.println("打印session:"+request.getSession().getAttribute("test"));
		}
		return "hi,你好，session中的值 ："+request.getSession().getAttribute("test");
	}
	
	@RequestMapping(value="/hi")
	public String sayHi(@RequestParam String name){
		return "hi,"+name;
	}

	@RequestMapping(value="/getMap/{name}")
	public Map getMap(@PathVariable String name){
		Map map = new HashMap();
		map.put("name", name);
		return map;
	}
	
	
	@RequestMapping(value="/testMap")
	public Map getMap(){
		String a = request.getParameter("a");
		System.out.println(a);
		System.out.println(request.getParameterMap());
		Map map = new HashMap();
//		map.put("name", name);
		return map;
	}
	
	
	@RequestMapping(value = "/post", method = RequestMethod.POST, produces="application/json", consumes="application/json")
	@ResponseBody
	public String post(@RequestBody String json) {
		System.out.println(json);
	    return json;
	}
}
